package com.bwf.lgqingdan.mvp.presenter.impl;

import com.bwf.lgqingdan.entity.ArticlesBean;
import com.bwf.lgqingdan.mvp.model.SearchArticleListModel;
import com.bwf.lgqingdan.mvp.model.impl.SearchArticleListModelImpl;
import com.bwf.lgqingdan.mvp.presenter.SearchArticleListPresenter;
import com.bwf.lgqingdan.mvp.view.SearchDataListView;

import java.util.List;

/**
 * Created by Administrator on 2016/11/20.
 */

public class SearchArticleListPresenterImpl implements SearchArticleListPresenter, SearchArticleListModel.Callback {
    private SearchArticleListModel model;
    private SearchDataListView view;

    public SearchArticleListPresenterImpl(SearchDataListView view) {
        this.view = view;
        this.model = new SearchArticleListModelImpl();
    }

    @Override
    public void loadData(String keyword) {
        view.showLoading();
        model.loadData(keyword,this);
    }

    @Override
    public void loadSuccess(List<ArticlesBean> articles) {
        view.hideLoading();
        if(articles == null || articles.size() == 0){
            view.clearListDatas();
            view.showNoDataLayout();
        }else{
            view.showData(articles);
            view.hideNoDataLayout();
        }
    }

    @Override
    public void loadFailed(String failedMsg) {
        view.showLoadFailed(failedMsg);
        view.hideLoading();
    }
}
